/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.iti.jets.gpts.dto.assist;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author mustafajnr
 */
public class TranServiceFullUsage {
    
    List<TranServiceUsage> tranServiceUsages;

    public TranServiceFullUsage(String string) {
        tranServiceUsages = new ArrayList<TranServiceUsage>();
        Pattern pattern = Pattern.compile("[(]\\d+,\\d+,\\d+,\\d+[)]");
        Matcher matcher = pattern.matcher(string);
        while (matcher.find()) {
            tranServiceUsages.add(new TranServiceUsage(matcher.group()));
        }
    }

    @Override
    public String toString() {
        return "TranServiceFullUsage{" + "tranServiceUsages=" + tranServiceUsages + '}';
    }
    
    
    public String toJSON() {
        if (tranServiceUsages == null || tranServiceUsages.isEmpty()) return "[]";
        String result = "[";
        for (TranServiceUsage tranServiceUsage : tranServiceUsages) {
            result += tranServiceUsage.toJSON() + ",";
        }
        return result.substring(0, result.lastIndexOf(',')) + ']';
    }
    
}
